package com.admin.socketmultiplayer.activity

import android.widget.ImageView
import cn.bmob.v3.BmobQuery
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.FindListener
import com.admin.socketmultiplayer.R
import com.admin.socketmultiplayer.adapter.RoomListAdapter
import com.admin.socketmultiplayer.bean.Room
import kotlinx.android.synthetic.main.activity_room_list.*
import kotlinx.android.synthetic.main.layout_title.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast

/**
 * Created by 吴昶 on 2018/5/15.
 */
class RoomListActivity:BaseActivity(){

    var roomAdapter: RoomListAdapter?=null

    override fun bindLayout(): Int {
        return R.layout.activity_room_list
    }

    override fun initData() {
        tv_title.text="房间列表"
        var query= BmobQuery<Room>()

        roomAdapter= RoomListAdapter(this, R.layout.layout_room_list_item,null,object:RoomListAdapter.RoomItemClickListener{
            override fun OnItemClickListener(room: Room, image: ImageView, position: Int) {
                startActivity<ArenaActivity>("roomId" to room.objectId)
            }
        })
        lv_room_list.adapter=roomAdapter
        query.findObjects(object : FindListener<Room>(){
            override fun done(p0: MutableList<Room>?, p1: BmobException?) {
                p0?.let {
                    roomAdapter!!.upData(p0)
                }
            }
        })
    }

    override fun initEvent() {
        btn_random_matching.setOnClickListener {
            toast("功能开发中，请稍后")
        }
    }

}